<template>
  <header class="header">
    <h1>我的记事本</h1>
    <input
      v-model.trim="name"
      placeholder="请输入任务"
      class="new-todo"
      @keyup.enter="handleAdd"
    />
    <button class="add" @click="handleAdd">添加任务</button>
  </header>
</template>

<script>
export default {
  data() {
    return {
      name: "",
    };
  },
  methods: {
    handleAdd() {
      if (this.name === "") {
        alert("请输入任务！");
        return;
      }
      this.$emit("add", this.name);
      this.name = "";
    },
  },
};
</script>

<style>
</style>